#include "queue.h"
#include "head.h"

int enQueue(queue_t *pQueue,int net_fd){

    //创建新结点，必须在堆空间创建
    //node_t new_node;错误
    node_t* new_node =(node_t*)calloc(1,sizeof(node_t));
    new_node->net_fd = net_fd;

    if(pQueue->size == 0){
        pQueue->head = new_node;
        pQueue->end = new_node;
    }else{
        pQueue->end->pNext = new_node;
        pQueue->end = new_node;
    }

    pQueue->size++;

    return 0;
}

int deQueue(queue_t *pQueue){

    if(pQueue->size == 0){
        return -1;
    }

    node_t* p = pQueue->head;

    pQueue->size--;
    pQueue->head = pQueue->head->pNext;
    
    if(pQueue->size == 1){
        pQueue->end = NULL;
    }
    
    free(p);
    return 0;
}